﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using Hangjing.Common;
using Hangjing.Model;
using Hangjing.SQLServerDAL;
using Hangjing.Weixin;

/// <summary>
/// 商家 后台页面基类
/// </summary>
public class shopPageBase : System.Web.UI.Page, System.Web.SessionState.IRequiresSessionState
{
    /// <summary>
    /// 用户微信对应公众平台唯一编号
    /// </summary>
    public string openid = "";

    public PointsInfo user = null;

    /// <summary>
    /// BasePage类构造函数
    /// </summary>
    public shopPageBase()
    {
        this.PreRender += new System.EventHandler(Page_PreRender);
    }

    void Page_PreRender(object sender, EventArgs e)
    {
        //将时间戳保存在hiddenfield中
    }
    /// <summary>
    /// 初始化，这个时间生成session对像
    /// </summary>
    /// <param name="e"></param>
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        openid = Request.QueryString["openid"];
        if (openid != null && openid.Length > 0)
        {
            WebUtility.FixsetCookie("shopopenid", openid, 365);
        }
        else
        {
            openid = WebUtility.FixgetCookie("shopopenid");
        }

        UserHelp.IsLogin_Togo(Request.Url.PathAndQuery);


        if (WebUtility.isWeiXin() && (openid == null || openid == ""))
        {

            WebUtility.FixsetCookie("reurl", Request.Url.ToString(), 365);

            Hangjing.Common.HJlog.toLog("reurl" + Request.Url.ToString());

            PointsInfo user = UserHelp.GetUser_Togo();
            WebOAuth auth=   new Hangjing.Weixin.WebOAuth(Context,true);

            auth.shopAuth(user.cityid, user.Unid);

            return;
        }

    }

}

